<?php
require_once('Extension/Controller/Action.php');

// to test :
// http://kbs.info/ajax/user/check-login/login/XXX

class Ajax_UserController extends Extension_Controller_Action
{
    public function indexAction()
    {
        $this->_forward('check-login');
    }

    public function checkLoginAction()
    {
        if ($this->getRequest()->isXmlHttpRequest()) {

            $login = $this->_getParam('login', '');

            if ($login != '') {

                require_once('Core/Model/Function/User.php');
                $functionUser = new Core_Model_Function_User();
                $result = $functionUser->getUserByLogin($login);

                if ($result != NULL) {
                    $result = $this->view->T('user exists !');
                } else {
                    $result = $this->view->T('user not exists !');
                }
            } else {
                $result = $this->view->T('* required');
            }
     
            //$this->view->result = $result;
            $this->getHelper('Json')->sendJson($result);

            //$this->getHelper('autoCompleteDojo')->sendAutoCompletion($result);
            //$this->_helper->autoCompleteDojo($data);

        } else {
            echo $this->view->T('it is not XmlHttpRequest');
            exit;
        }
    }


}